<include file="public@header"/>
<style type="text/css">

  .item {
    float: left;
    clear: both;
    margin-bottom: 5px;
  }
  /* 向上的箭头 */

  .arrow-top {
    font-size: 0;
    line-height: 0;
    border-width: 5px;
    border-color: #18BC9C;
    border-top-width: 0;
    border-style: dashed;
    border-bottom-style: solid;
    border-left-color: transparent;
    border-right-color: transparent;
  }

  /* 向下的箭头 */

  .arrow-bottom {
    font-size: 0;
    line-height: 0;
    border-width: 5px;
    border-color: #18BC9C;
    border-bottom-width: 0;
    border-style: dashed;
    border-top-style: solid;
    border-left-color: transparent;
    border-right-color: transparent;
  }


  .fl{
    float: left;
  }
  .fr{
    float: right;
  }
  .clear{
    clear: both;
  }
</style>
</head>
<body>
<div class="wrap">
  <ul class="nav nav-tabs">
    <li class="active"><a>{:lang('USER_INDEXADMIN_INDEX')}</a></li>
    <li><a href="{:url('adminIndex/add')}">添加主播</a></li>
  </ul>
  <form name="search" class="well form-inline margin-top-20" method="post" action="{:url('user/adminIndex/index')}">
    性别：
    <select class="form-control" name="sex" style="width: 100px;">
      <option value=''>不限</option>
      <option value="1" <if condition="input('request.sex') neq '' && input('request.sex') eq 1">selected</if>>男</option>
      <option value="2" <if condition="input('request.sex') neq '' && input('request.sex') eq 2">selected</if>>女</option>

    </select>
    超管：
    <select class="form-control" name="issuper">
      <option value="">全部</option>
      <option value="1" <if condition="input('request.issuper') neq '' && input('request.issuper') eq 1">selected</if>>是</option>
      <option value="0" <if condition="input('request.issuper') neq '' && input('request.issuper') eq 0">selected</if>>否</option>
    </select>

    注册时间：
    <input class="form-control js-bootstrap-date" name="start_time" id="start_time" value="{:input('request.start_time')}" aria-invalid="false" style="width: 110px;"> -
    <input class="form-control js-bootstrap-date" name="end_time" id="end_time" value="{:input('request.end_time')}" aria-invalid="false" style="width: 110px;">
    用户ID：
    <input class="form-control" type="text" name="uid" style="width: 200px;" value="{:input('request.uid')}"
           placeholder="请输入用户ID">
    关键字：
    <input class="form-control" type="text" name="keyword" style="width: 200px;" value="{:input('request.keyword')}"
           placeholder="用户名/昵称/手机">
    <input class="form-control" type="hidden" name="coin_status" value="{:input('request.coin_status')}" >
    <input class="form-control" type="hidden" name="consumption_status" value="{:input('request.consumption_status')}" >
    <input class="form-control" type="hidden" name="votes_status" value="{:input('request.votes_status')}" >
    <input class="form-control" type="hidden" name="votestotal_status" value="{:input('request.votestotal_status')}" >
    <input class="form-control" type="hidden" name="createtime_status" value="{:input('request.createtime_status')}" >

    <input type="submit" class="btn btn-primary" value="搜索"/>
    <a class="btn btn-danger" href="{:url('user/adminIndex/index')}">清空</a>
    <br>
    <br>
    用户数：{$nums}  (根据条件统计)
  </form>
  <form method="post" class="js-ajax-form">
    <table class="table table-hover table-bordered">
      <thead>
      <tr>
        <th>ID</th>
        <th>{:lang('USERNAME')}</th>
        <th>{:lang('NICENAME')}</th>
        <th>{:lang('AVATAR')}</th>
        <th>性别</th>
        <th class="coin_top">
          <p class="fl">{$configpub['name_coin']}</p>
          <p class="fr">
            <if condition="$coin_status neq '1'"><span class="item arrow-top" title="从低到高排序"></span></if>
            <if condition="$coin_status neq '-1'"><span class="item arrow-bottom" title="从高到底排序"></span></if>
          </p>
          <p class="clear"></p>

        </th>
        <th class="consumption_top">
          <p class="fl">总消费</p>
          <p class="fr">
            <if condition="$consumption_status neq '1'"><span class="item arrow-top" title="从低到高排序"></span></if>
            <if condition="$consumption_status neq '-1'"><span class="item arrow-bottom" title="从高到底排序"></span></if>
          </p>
          <p class="clear"></p>
        </th>
        <th class="votes_top">
          <p class="fl">{$configpub['name_votes']}</p>
          <p class="fr">
            <if condition="$votes_status neq '1'"><span class="item arrow-top" title="从低到高排序"></span></if>
            <if condition="$votes_status neq '-1'"><span class="item arrow-bottom" title="从高到底排序"></span></if>
          </p>
          <p class="clear"></p>
        </th>
        <th class="votestotal_top">
          <p class="fl">总收益</p>
          <p class="fr">
            <if condition="$votestotal_status neq '1'"><span class="item arrow-top" title="从低到高排序"></span></if>
            <if condition="$votestotal_status neq '-1'"><span class="item arrow-bottom" title="从高到底排序"></span></if>
          </p>
          <p class="clear"></p>
        </th>
        <th>手机</th>
        <th>推荐值</th>
        <th>实名认证</th>
        <!--                <th>主播认证</th>-->
        <th class="createtime_top">
          <p class="fl">{:lang('REGISTRATION_TIME')}</p>
          <p class="fr">
            <if condition="$createtime_status neq '1'"><span class="item arrow-top" title="正序排序"></span></if>
            <if condition="$createtime_status neq '-1'"><span class="item arrow-bottom" title="倒序排序"></span></if>
          </p>
          <p class="clear"></p>
        </th>
        <th>{:lang('LAST_LOGIN_TIME')}</th>
        <th>{:lang('LAST_LOGIN_IP')}</th>
        <th>{:lang('STATUS')}</th>
        <th>{:lang('ACTIONS')}</th>
      </tr>
      </thead>
      <tbody>
      <php>
        $user_statuses=array("0"=>lang('USER_STATUS_BLOCKED'),"1"=>lang('USER_STATUS_ACTIVATED'),"2"=>lang('USER_STATUS_UNVERIFIED'),"3"=>'已注销');
        $user_auth=array('0'=>'×','1'=>'√');
        $author_auth=array('0'=>'×','1'=>'√');
      </php>
      <foreach name="list['data']" item="vo">
        <tr>
          <td>{$vo.id}</td>
          <td>{$vo['user_login']?$vo['user_login']:($vo['mobile']?$vo['mobile']:lang('THIRD_PARTY_USER'))}
          </td>
          <td>{$vo['user_nickname']?$vo['user_nickname']:lang('NOT_FILLED')}</td>
          <td><img width="25" height="25" src="{:get_upload_path($vo['avatar'])}"/></td>
          <td><if condition="$vo['sex'] eq 1">男<elseif condition="$vo['sex'] eq '2'"/>女<else />未设置</if></td>
          <td>{$vo.coin}</td>
          <td>{$vo.consumption}</td>
          <td>{$vo.votes}</td>
          <td>{$vo.votestotal}</td>
          <td>{$vo.mobile}</td>
          <td>{$vo.recommend_val}</td>
          <td>{$user_auth[$vo.isauth]}</td>
          <!--                    <td>{$author_auth[$vo.isauthor_auth]}</td>-->
          <td>{:date('Y-m-d H:i:s',$vo['create_time'])}</td>
          <td><if condition="$vo['last_login_time'] gt 0">{:date('Y-m-d H:i:s',$vo['last_login_time'])}</if></td>
          <td>{$vo.last_login_ip}</td>
          <td>
            <switch name="vo.user_status">
              <case value="0">
                <span class="label label-danger">{$user_statuses[$vo['user_status']]}</span>
              </case>
              <case value="1">
                <span class="label label-success">{$user_statuses[$vo['user_status']]}</span>
              </case>
              <case value="2">
                <span class="label label-warning">{$user_statuses[$vo['user_status']]}</span>
              </case>
              <case value="3">
                <span class="label label-warning">{$user_statuses[$vo['user_status']]}</span>
              </case>
            </switch>
          </td>
          <td>
            <if condition="$vo.user_status neq '3'">

              <if condition="$vo.isauth">
                <a class="btn btn-xs btn-danger js-ajax-dialog-btn"
                   href="{:url('adminIndex/cancelUserAuth',array('id'=>$vo['id']))}"
                   data-msg="确定要取消实名认证吗？<br />取消后主播认证也将被取消。">取消实名认证
                </a>
              </if>

              <!--                            <if condition="$vo.isauthor_auth">-->
              <a class="btn btn-xs btn-info  setrecommend" data-uid="{$vo.id}" data-value="{$vo.recommend_val}">推荐值</a>
              <!--                                <a class="btn btn-xs btn-danger js-ajax-dialog-btn"-->
              <!--                                   href="{:url('adminIndex/cancelAuthorAuth',array('id'=>$vo['id']))}"-->
              <!--                                   data-msg="确定要取消主播认证吗？">取消主播认证-->
              <!--                                </a>-->
              <!--                            </if>-->

              <if condition="$vo.issuper eq '1'">
                <a class="btn btn-xs btn-info js-ajax-dialog-btn"
                   href="{:url('adminIndex/setsuper',array('id'=>$vo['id'],'issuper'=>0))}">取消超管</a>
                <else/>
                <a class="btn btn-xs btn-info js-ajax-dialog-btn"
                   href="{:url('adminIndex/setsuper',array('id'=>$vo['id'],'issuper'=>1))}">设置超管</a>
              </if>

              <else/>
              <!--								<a class="btn btn-xs btn-warning forbidden"-->
              <!--								   href="{:url('adminIndex/ban',array('id'=>$vo['id']))}"-->
              <!--								   data-msg="{:lang('BLOCK_USER_CONFIRM_MESSAGE')}">{:lang('BLOCK_USER')}1</a>-->


              </empty>
            </if>
            <if condition="$vo['forbiddenStatus'] eq '1' ">
              <a class="btn btn-xs btn-success unForbidden"
                 data-id="{$vo['id']}">{:lang('ACTIVATE_USER')}</a>
              <else/>
              <a class="btn btn-xs btn-warning forbidden" data-id="{$vo['id']}" >{:lang('BLOCK_USER')}</a>
            </if>


            <a class="btn btn-xs btn-primary" href='{:url("adminIndex/edit",array("id"=>$vo["id"]))}'>{:lang('EDIT')}</a>
            <a class="btn btn-xs btn-danger js-ajax-delete" href="{:url('adminIndex/del',array('id'=>$vo['id']))}">{:lang('DELETE')}</a>
          </td>
        </tr>
      </foreach>
      </tbody>
    </table>
    <div class="pagination">{$page}</div>
  </form>
</div>
<script type="text/html" id="barDemo">
  <div class="wrap">
    <div class="form-horizontal js-ajax-form margin-top-20">
      <div class="form-group">
        <label for="cycle" class="col-sm-2 control-label"><span class="form-required">*</span>禁用期限</label>
        <div class="col-md-6 col-sm-10">
          <select class="form-control" name="cycle" id="cycle">
            <option value="0">--请选择禁用期限--</option>
            <option value="1">1天</option>
            <option value="7">7天</option>
            <option value="30">30天</option>
            <option value="180">180天</option>
            <option value="-1">永久</option>
          </select>
        </div>
      </div>

      <div class="form-group">
        <label for="remark" class="col-sm-2 control-label"><span class="form-required">*</span>禁用原因</label>
        <div class="col-md-6 col-sm-10">
          <textarea class="form-control" name="remark" id="remark"></textarea>
        </div>
      </div>
    </div>
  </div>
</script>
<script src="__STATIC__/js/admin.js"></script>
<script>
  $(function(){

    Wind.use('layer');

    // 禁用
    $('.forbidden').click(function () {
      var userId = $(this).data('id');
      var layID = layer.open({
        type: 1, // page 层类型
        area: ['500px', '300px'],
        title: '禁用',
        shade: 0.6, // 遮罩透明度
        shadeClose: true, // 点击遮罩区域，关闭弹层
        maxmin: true, // 允许全屏最小化
        anim: 0, // 0-6 的动画形式，-1 不开启
        content: $('#barDemo').html(),
        btn: ['确定', '关闭'],
        // 按钮1 的回调
        btn1: function(index, layero, that){

          var cycle = $('#cycle').val();
          var remark = $('#remark').val();
          if (cycle === '0' || cycle === '') {
            alert("请选择禁用周期");
            return false;
          }

          if (remark === '') {
            alert("请填写禁用原因");
            return false;
          }
          var params = {
            userId : userId,
            cycle : cycle,
            remark : remark
          }
          $.post('{:url("adminIndex/setForbidden")}',params,function (res) {
            if (res.code === 0) {
              alert("禁用成功");
              window.location = window.location;
            }
          }, 'JSON');
        },
        btn2: function(index, layero, that){
          layer.closeAll();
        },
      });
    });
    $('.unForbidden').click(function () {
      var userId = $(this).data('id');
      layer.confirm();
      layer.confirm('确定要解除禁用吗?', {
        btn: ['确定','取消'] //按钮
      }, function(){
        var params = {
          userId : userId,
        }
        $.post('{:url("adminIndex/setUnForbidden")}',params,function (res) {
          if (res.code === 0) {
            alert("解禁成功");
            window.location = window.location;
          }
        }, 'JSON');
      }, function(){
        layer.close(layer.index);
      });


    });



    $('.setrecommend').click(function(){
      var _this=$(this);
      var uid=_this.data('uid');
      var recommend=_this.data('value');

      layer.prompt({
        formType: 0,
        title: '推荐值',
        value: recommend,
      }, function(value, index, elem){
        $.ajax({
          url:'{:url('user/adminIndex/setrecommend')}',
                type:'POST',
                data:{uid:uid,recommend:value},
        dataType:'json',
                success:function(data){
          var code=data.code;
          if(code==0){
            layer.msg(data.msg);
            return !1;
          }
          layer.msg(data.msg,{},function(){
            layer.closeAll();
            location.reload();
          });

        },
        error:function(){
          layer.msg('操作失败，请重试')
        }
      });

      });

    });

    //钻石由低到高排序
    $(".coin_top .arrow-top").on('click',function(){
      //layer.msg("钻石向上");
      change_status('coin','1');
    });
    //钻石由高到低排序
    $(".coin_top .arrow-bottom").on('click',function(){
      //layer.msg("钻石向下");
      change_status('coin','-1');
    });

    //总消费由低到高排序
    $(".consumption_top .arrow-top").on('click',function(){
      //layer.msg("总消费向上");
      change_status('consumption','1');
    });

    //总消费由高到低排序
    $(".consumption_top .arrow-bottom").on('click',function(){
      //layer.msg("总消费向下");
      change_status('consumption','-1');
    });

    //映票由低到高排序
    $(".votes_top .arrow-top").on('click',function(){
      //layer.msg("映票向上");
      change_status('votes','1');
    });

    //映票由高到低排序
    $(".votes_top .arrow-bottom").on('click',function(){
      //layer.msg("映票向下");
      change_status('votes','-1');
    });


    //总收益由低到高排序
    $(".votestotal_top .arrow-top").on('click',function(){
      //layer.msg("总收益向上");
      change_status('votestotal','1');
    });

    //总收益由高到低排序
    $(".votestotal_top .arrow-bottom").on('click',function(){
      //layer.msg("总收益向下");
      change_status('votestotal','-1');
    });

    //注册时间正序排序
    $(".createtime_top .arrow-top").on('click',function(){
      //layer.msg("正序");
      change_status('createtime','1');
    });

    //注册时间倒序排序
    $(".createtime_top .arrow-bottom").on('click',function(){
      //layer.msg("倒序");
      change_status('createtime','-1');
    });
  })

  function change_status(current,val){
    $("input[name='"+current+"_status']").val(val);
    var arr=['coin','consumption','votes','votestotal','createtime'];
    for (var i = 0; i < arr.length; i++) {
      if(arr[i]!=current){
        $("input[name='"+arr[i]+"_status']").val('');
      }
    }

    $("form[name='search']").submit();
  }
</script>
</body>
</html>